#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class Solution
{

public:
    bool isNStraightHand(vector<int> &hand, int groupSize)
    {

        sort(hand.begin(), hand.end());
        int size = hand.size();
        if (size % groupSize != 0)
            return false;
        unordered_map<int, int> hash;
        for (int i = 0; i < size; i++)
        {
            hash[hand[i]]++;
        }
        for (int i = 0; i < size; i++)
        {
            if (hash[hand[i]] != 0)
            {
                for (int j = 0; j < groupSize; j++)
                {
                    if (hash[hand[i] + j] == 0)
                        return false;
                    hash[hand[i] + j]--;
                }
            }
        }
        return true;
    }
};